package validator.handle;

import java.lang.annotation.Annotation;

import validator.annotation.Pattern;
import validator.exception.ValidateException;

public class PatternValidator implements Validator {

	@Override
	public boolean isValid(Class<?> clazz) {
		return CharSequence.class.isAssignableFrom(clazz);
	}

	@Override
	public void validate(Annotation annotation, Object v) {
		Pattern anno = (Pattern) annotation;
		if (!v.toString().matches(anno.regex()))
			throw new ValidateException(anno.value());
	}

}
